package cn.edu.hnnu.c.rentacar.dao.hibernateimpl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import cn.edu.hnnu.c.rentacar.beans.CheckRecord;
import cn.edu.hnnu.c.rentacar.idao.ICheckRecordDAO;
import cn.edu.hnnu.c.rentacar.util.HibernateUtil;

public class CheckRecordDAOHibernateImpl implements ICheckRecordDAO {
	private static CheckRecordDAOHibernateImpl instance;
	
	private CheckRecordDAOHibernateImpl(){
		
	}
	
	public static CheckRecordDAOHibernateImpl getInstance(){
		if(null==instance){
			instance = new CheckRecordDAOHibernateImpl();
		}
		return instance;
	}
	
	
	
	@Override
	public boolean addCheckRecord(CheckRecord checkRecord) {
		SessionFactory factory = null;
		Session session = null;
		Transaction tran = null;
		
		try {
			factory = HibernateUtil.getSessionFactory();
			session = factory.openSession();
			tran = session.beginTransaction();
			session.save(checkRecord);
			tran.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tran.rollback();
			return false;
		}finally{
			session.close();
		}
		return true;
	}

	@Override
	public boolean deleteCheckRecordById(int checkRecordId) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public CheckRecord getCheckRecordById(int checkRecordId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<CheckRecord> getAllCheckRecords() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean updateCheckRecord() {
		// TODO Auto-generated method stub
		return false;
	}

}
